
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <strings.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <sys/fcntl.h>

int main(int argc, char ** argv) {


    pid_t pid;
    int pipefd[2];
    pipe(pipefd);

    if ((pid = fork()) == 0) {

        while (1) {
        
            char buf[2];
            bzero(buf, 2);
            int n = read(pipefd[0], buf, 2);
            if (n == 0) {

                break;
            }
            printf("%s and errno : %d\n", buf, errno);
        }
        return 0;
    }
    printf("result pid : %d", pid);
    int index = 0;

    while (index < 9) {

        write(pipefd[1], "1", 1);
        index++;
        sleep(1);
    }
    
    return EXIT_SUCCESS;
}
